package com.example.ice.fittime.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

/**
 * Created by Administrator on 2016/10/13.
 */

public class HomePagerAdapter extends PagerAdapter {
    private Context context;
    private List<ImageView> imageViewList;
    public HomePagerAdapter(Context context, List<ImageView> imageViewList) {
        this.context = context;
        this.imageViewList = imageViewList;
    }

    @Override
    public int getCount() {
        return imageViewList == null?0:5000000;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view.equals(object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        int newPosition = position % imageViewList.size();
        ImageView imageView = imageViewList.get(newPosition);
        container.addView(imageView);
        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
    }
}
